package com.cy.pj.goods.controller;

import com.cy.pj.goods.pojo.Goods;
import com.cy.pj.goods.service.GoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/goods/")
public class GoodsController {

    @Autowired
    private GoodsService goodsService;

    @RequestMapping("doFindGoods")
    public List<Goods> doFindGoods(){
        System.out.println("ok");
        return goodsService.findGoods();
    }
    @RequestMapping("doDeleteGoods/{id}")
    public String doDeleteById(@PathVariable("id") Integer id){
        goodsService.doDeleteById(id);
        return "delete ok";
    }
    @RequestMapping("doFindById/{id}")
    public Goods doFindById(@PathVariable("id") Integer id){
        return goodsService.findById(id);
    }
    @RequestMapping("doSaveGoods")
    public String doSaveGoods(@RequestBody Goods goods){
        goodsService.insertGoods(goods);
        return "Save ok";
    }
    @RequestMapping("doUpdateGoods")
    public String doUpdateGoods(@RequestBody Goods goods){
        goodsService.updateGoods(goods);
        return "updata ok";
    }
}
